Imports System.Text.RegularExpressions


'<Serializable()> _
'Public Class EntrezLinkList
'    Inherits List(Of EntrezLink)



'    Public Sub New()

'    End Sub

'    Public Sub New(ByVal links As String)

'        Dim linkArray As String() = links.Split(";"c)

'        For Each link As String In linkArray

'            Me.Add(New EntrezLink(link))

'        Next

'    End Sub

'    Public ReadOnly Property SingleDatabase() As Boolean
'        Get

'            If Me.Count > 0 Then


'                Dim prevDb As String = Me(0).Database

'                For Each link As EntrezLink In Me

'                    If Not link.Database.Equals _
'                        (prevDb, StringComparison.InvariantCultureIgnoreCase) Then Return False

'                Next

'            End If


'            Return True

'        End Get
'    End Property


'    Public Function IdsToArray() As Integer()

'        Dim ids As New List(Of Integer)

'        For Each link As EntrezLink In Me

'            ids.Add(link.ArticleId)

'        Next

'        Return ids.ToArray

'    End Function


'    Public Shadows Sub Add(ByVal link As EntrezLink)

'        If Not Me.Contains(link) Then

'            MyBase.Add(link)

'        End If

'    End Sub

'    Public Overloads Sub AddRange(ByVal ids As Integer(), ByVal dbName As String)

'        For Each id As Integer In ids

'            Me.Add(New EntrezLink(id, dbName))

'        Next

'    End Sub

'    Public Overloads Function Contains(ByVal id As Integer) As Boolean
'        For Each link As EntrezLink In Me

'            If link.ArticleId = id Then Return True

'        Next

'        Return False

'    End Function


'    Public Overloads Sub Remove(ByVal id As Integer)

'        Dim index As Integer = 0
'        Dim found As Boolean = False

'        For Each link As EntrezLink In Me

'            If link.ArticleId = id Then

'                found = True

'                Exit For

'            End If

'            index += 1

'        Next

'        If found Then Me.RemoveAt(index)

'    End Sub

'    Public Overrides Function ToString() As String

'        Dim links As New Text.StringBuilder

'        For Each link As EntrezLink In Me

'            links.Append(link.ToString)

'        Next

'        Return links.ToString

'    End Function

'End Class


'Public Class EntrezLinkDictionary
'    Inherits Dictionary(Of Integer, String)


'    Private Const toStringFormat As String = "{0}:{1};"
'    Private Const stringPattern As String = "^(\d+):(\w+);?$"
'    Private Const linkUrl As String = _
'        "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi{0}"

'    Private Const queryString As String = _
'        "?cmd=Retrieve&db={1}&dopt=Abstract&list_uids={0}&query_hl=1"


'    Public Overloads Sub AddRange(ByVal ids As Integer(), ByVal dbName As String)

'        For Each id As Integer In ids

'            Me.Add(id, dbName)

'        Next


'    End Sub

'    Public ReadOnly Property Url(ByVal key As Integer) As String
'        Get

'            Return String.Format(linkUrl, String.Format(queryString, key, Me.Item(key)))

'        End Get
'    End Property

'    Public Overloads Function ToString(ByVal key As Integer) As String

'        Return String.Format(toStringFormat, key, Me.Item(key))

'    End Function


'    Public Function ToKeyValuePair(ByVal key As Integer) As KeyValuePair(Of Integer, String)

'        Return New KeyValuePair(Of Integer, String)(key, Me.Item(key))

'    End Function


'End Class


'<Serializable()> _
'Public Class EntrezLink

'    Private Const toStringFormat As String = "{0}:{1};"
'    Private Const stringPattern As String = "^(\d+):(\w+);?$"

'    Private linkPair As New KeyValuePair(Of Integer, String)


'    Private Const linkUrl As String = _
'        "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi{0}"

'    Private Const queryString As String = _
'        "?cmd=Retrieve&db={1}&dopt=Abstract&list_uids={0}&query_hl=1"

'    'Private articleIdField As Integer

'    'Private databaseField As String

'    Public Sub New()

'    End Sub

'    Public Sub New(ByVal link As KeyValuePair(Of Integer, String))
'        Me.linkPair = link

'    End Sub

'    Public Sub New(ByVal link As String)

'        Dim matches As Match = Regex.Match(link, stringPattern)

'        If matches.Groups.Count = 3 Then

'            Me.linkPair = New KeyValuePair(Of Integer, String) _
'                (Convert.ToInt32(matches.Groups(1).Value), matches.Groups(2).Value)



'            'Me.articleIdField = Convert.ToInt32(matches.Groups(1).Value)
'            'Me.databaseField = matches.Groups(2).Value

'        Else

'            Throw New ArgumentException("Invalid link string provided to constructor.")

'        End If

'    End Sub

'    Public Sub New(ByVal id As Integer, ByVal dbName As String)
'        'Me.articleIdField = id

'        'Me.databaseField = dbName

'        Me.linkPair = New KeyValuePair(Of Integer, String)(id, dbName)


'    End Sub

'    Public ReadOnly Property ArticleId() As Integer
'        Get
'            'Return Me.articleIdField
'            Return Me.linkPair.Key
'        End Get

'    End Property

'    Public ReadOnly Property Database() As String
'        Get
'            'Return Me.databaseField
'            Return Me.linkPair.Value

'        End Get
'    End Property

'    Public ReadOnly Property Url() As String
'        Get

'            Return String.Format(linkUrl, String.Format(queryString, Me.ArticleId, Me.Database))

'        End Get
'    End Property

'    Public Overrides Function ToString() As String

'        Return String.Format(toStringFormat, Me.ArticleId, Me.Database)

'    End Function

'    Public Overrides Function Equals(ByVal obj As Object) As Boolean

'        If TypeOf obj Is EntrezLink Then

'            Return Me.ArticleId = DirectCast(obj, EntrezLink).ArticleId

'        Else

'            Return False

'        End If

'    End Function

'    Public Overrides Function GetHashCode() As Integer

'        Return Me.ArticleId.GetHashCode

'    End Function

'    Public Shared Operator =(ByVal link1 As EntrezLink, ByVal link2 As EntrezLink) As Boolean

'        Return link1.ArticleId = link2.ArticleId

'    End Operator

'    Public Shared Operator <>(ByVal link1 As EntrezLink, ByVal link2 As EntrezLink) As Boolean

'        Return Not link1 = link2

'    End Operator

'End Class